package 力扣日常刷题.木22二月.第02天207;

/**
 * @author 帅小伙
 * @date 2022/2/7
 * @description
 * 三视图   不遮挡别人
 * 横竖最大的最小值
 */
public class Demo25贪心保持城市天际线 {


    public int maxIncreaseKeepingSkyline(int[][] grid) {
        int n = grid.length;
        int row[] = new int[n];
        int line[] = new int[n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(row[i] < grid[i][j]) row[i] = grid[i][j];
                if(line[i] < grid[j][i]) line[i] = grid[j][i];
            }
        }

        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int min = Math.min(row[i],line[j]);
                ans += (min - grid[i][j]);
            }
        }
        return ans;
    }
}
